package cn.yanji.service.impl.element;

import cn.yanji.service.ExecuteService;
import cn.yanji.service.element.ChapterService;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yanji w2c17lin@qq.com
 * @since 2018/11/7 上午 10:26
 */
@Service
public class TopicServiceImpl implements ChapterService {

	private @Autowired ExecuteService executeService;

	@Override
	public List<WebElement> chapters(String subject, String type) {
		String url = (StringUtils.equals(SUBJECT_1, subject) ? CHAPTER_URL_S1 : CHAPTER_URL_S4) +
				"?" + "title=" + type + "　" + subject;
		executeService.go(url);
		return executeService.webDriver().findElements(By.xpath("//div[@id='divMain']//div[@class='divCh']//a[@name='arec']"));
	}
}
